package com.itheima.service.Impl;

import com.itheima.dao.IRoleDao;
import com.itheima.domian.Permission;
import com.itheima.domian.Role;
import com.itheima.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private IRoleDao iRoleDao;

    @Override
    public List<Role> findAll() throws Exception {
        return iRoleDao.findAll();
    }

    @Override
    public void save(Role role) throws Exception {
         iRoleDao.save(role);
    }

    @Override
    public Role findById(String roleId)  throws  Exception{
        return iRoleDao.findById(roleId);
    }

    @Override
    public List<Permission> findOtherPermissions(String roleId) throws Exception {
        return iRoleDao.findOtherPermission(roleId);
    }

    @Override
    public void addRoleToPermission(String roleId, String[] permissionIds) throws Exception {
        for (String permissionid:permissionIds
             ) {
//            System.out.println("role:"+roleId);
//            System.out.println("permissionid"+permissionid);
            iRoleDao.addRoleToPermission(roleId,permissionid);
//            System.out.println(2);
        }
    }

}
